package main

func minimumDeleteSum(s1 string, s2 string) int {
	m := len(s1)
	n := len(s2)
	dp := make([][]int, m+1)
	for i := range dp {
		dp[i] = make([]int, n+1)
	}
	for i := 1; i <= m; i++ {
		dp[i][0] = int(s1[i-1]) + dp[i-1][0]
	}
	for j := 1; j <= n; j++ {
		dp[0][j] = int(s2[j-1]) + dp[0][j-1]
	}

	for i := 1; i < m+1; i++ {
		for j := 1; j < n+1; j++ {
			if s1[i-1] == s2[j-1] {
				dp[i][j] = dp[i-1][j-1]
			} else {
				a := dp[i-1][j] + int(s1[i-1])
				b := dp[i][j-1] + int(s2[j-1])
				if a < b {
					dp[i][j] = a
				} else {
					dp[i][j] = b
				}
			}
		}
	}
	return dp[m][n]
}

func main() {
	ans := minimumDeleteSum("sea", "eat")
	println(ans)
}
